import Vue from 'vue'
import VueRouter from 'vue-router'
// 路由组件
// import Login from '@/views/login'
import Home from '@/views/home'
import User from '@/views/user'
import Video from '@/views/video'
import Question from '@/views/question'
// import store from '@/store/index.js'

// 引入工具模块
Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login')
  },
  {
    path: '/',
    name: 'layout',
    component: () => import('@/layout.vue'),
    children: [
      { path: '', name: 'home', component: Home },
      { path: '/question', name: 'question', component: Question },
      { path: '/video', name: 'video', component: Video },
      { path: '/user', name: 'user', component: User }
    ]
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search/index.vue')
  },
  {
    path: '/search/result',
    name: 'searchResult',
    component: () => import('@/views/search/result.vue')
  },
  // 文章详情
  {
    path: '/article/:id',
    name: 'article',
    component: () => import('@/views/article/index.vue')
  }
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]
const router = new VueRouter({
  routes
})
// // 设置导航守卫
// router.beforeEach((to, from, next) => {
//   // 获取用户信息
//   if (to.path.startsWith('/user')) {
//     if (store.state.token) {
//       next()
//     } else {
//       next({
//         path: '/login'
//       })
//     }
//   }
// })
export default router
